package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-20 14:47
 **/
public class LeetCode78 {

    public List<List<Integer>> subsets(int[] nums) {
        List<Integer> t = new ArrayList<>();
        List<List<Integer>> res = new ArrayList<>();
        dfs(0, nums, res, t);
        return res;
    }

    public void dfs(int cur, int[] nums, List<List<Integer>> res, List<Integer> t) {
        if (cur == nums.length) {
            res.add(new ArrayList<>(t));
            return;
        }
        t.add(nums[cur]);
        dfs(cur + 1, nums, res, t);
        t.remove(t.size() - 1);
        dfs(cur + 1, nums, res, t);
    }

    public static void main(String[] args) {
        LeetCode78 code = new LeetCode78();
        System.out.println(code.subsets(new int[]{1, 2, 3}));
    }

}
